package psn.zjk.common;

import lombok.SneakyThrows;

import java.util.*;
import java.util.concurrent.CyclicBarrier;

/**
 * @author zhangjk
 * @CREATE_TIME 2021/1/18 17:58
 */
public class T {

    static class A implements Runnable {
        CyclicBarrier barrierA;
        CyclicBarrier barrier;

        public A(CyclicBarrier barrierA,CyclicBarrier barrier) {
            this.barrierA = barrierA;
            this.barrier = barrier;
        }

        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                System.out.println('A');
                try {
                    barrierA.await();
                    barrierA.reset();
                    barrier.await();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    static class B implements Runnable {
        CyclicBarrier barrierA;
        CyclicBarrier barrierB;

        public B(CyclicBarrier barrierA, CyclicBarrier barrierB) {
            this.barrierA = barrierA;
            this.barrierB = barrierB;
        }

        @SneakyThrows
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                try {

                    barrierA.await();
                    System.out.println('B');
                    barrierB.await();
                    barrierB.reset();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    static class C implements Runnable {
        CyclicBarrier barrierB;
        CyclicBarrier barrier;

        public C(CyclicBarrier barrierB,CyclicBarrier barrier) {
            this.barrierB = barrierB;
            this.barrier = barrier;
        }

        @SneakyThrows
        @Override
        public void run() {
            for (int i = 0; i < 10; i++) {
                try {
                    barrierB.await();
                    System.out.println('C');
                    barrier.await();
                    barrier.reset();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static void main(String[] args) {
        HashMap<Object, Integer> map = new HashMap<>();
        map.put("",1);
        map.put("x",2);
        map.put("z",3);
        Set<Map.Entry<Object, Integer>> entries = map.entrySet();
        ArrayList<Map.Entry<Object, Integer>> objects = new ArrayList<>(entries);

        objects.sort((o1, o2) -> {
            return o1.getValue()-o2.getValue();
        });
        TreeMap treeMap=new TreeMap();
    }
}